﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Ex5.RealNumberValidator
{
    class RealNumberValidator
    {
        static void Main(string[] args)
        {
            string[] correctNumbers;
            string[] wrongNumbers;
            InitializeNumbers(out correctNumbers, out wrongNumbers);

            string expression = @"^(-?[1-9]*(0)?[1-9]*|-?[1-9]+(0)?[1-9]*\.?[0-9]+|0\.[0-9]*[1-9]+)$";
            Regex validator = new Regex(expression);

            Console.WriteLine("Correct Numbers");
            foreach (var number in correctNumbers)
            {
                bool isValid = validator.IsMatch(number);
                Console.WriteLine("{0,-15} -- {1,-10}",number,isValid);
            }
            Console.WriteLine(new string('-',25));
            Console.WriteLine("\nIncorrect Numbers");
            foreach (var number in wrongNumbers)
            {
                bool isValid = validator.IsMatch(number);
                Console.WriteLine("{0,-15} -- {1,-10}", number, isValid);
            }
        }

        private static void InitializeNumbers(out string[] correctNumbers, out string[] wrongNumbers)
        {
            correctNumbers = new string[6];
            correctNumbers[0] = "0";
            correctNumbers[1] = "33";
            correctNumbers[2] = "-2381.78132";
            correctNumbers[3] = "4.3347";
            correctNumbers[4] = "12.00";
            correctNumbers[5] = "0.34";

            wrongNumbers = new string[9];
            wrongNumbers[0] = "+3";
            wrongNumbers[1] = "24 543";
            wrongNumbers[2] = "01.23";
            wrongNumbers[3] = "12.";
            wrongNumbers[4] = "11,23";
            wrongNumbers[5] = "--2";
            wrongNumbers[6] = ".25";
            wrongNumbers[7] = "-.25";
            wrongNumbers[8] = "12e7";
        }
    }
}
